package com.example.ks.controller;

import com.example.ks.entity.Dept;
import com.example.ks.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
public class deptcontroller {
    @Autowired
    private deptservice deptService;

    // 新增部门
    @PostMapping
    public boolean addDept(@RequestBody Dept dept) {
        return deptService.save(dept);
    }

    // 删除部门
    @DeleteMapping("/{id}")
    public boolean deleteDept(@PathVariable Integer id) {
        return deptService.removeById(id);
    }

    // 修改部门
    @PutMapping
    public boolean updateDept(@RequestBody Dept dept) {
        return deptService.updateById(dept);
    }

    // 根据ID查询部门
    @GetMapping("/{id}")
    public Dept getDeptById(@PathVariable Integer id) {
        return deptService.getById(id);
    }

    // 查询所有部门
    @GetMapping
    public List<Dept> getAllDepts() {
        return deptService.list();
    }
}